<template>
    <div class="debris-list" v-loading="loading">
        <div class="input-box">
            <span class="input-title" style="margin-left:0px;">英雄名</span>
            <el-input
                placeholder="搜索英雄名称"
                @keyup.enter.native="selectChange"
                style="width:280px;"
                clearable
                v-model.trim="keyWord"
                @clear="inputClear">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-button type="primary" class="btn" style="margin-left:20px" @click="getList(1, 10)">查询</el-button>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" border style="width: 100%">
                <el-table-column fixed width="160" prop="name" label="英雄名"></el-table-column>
                <el-table-column fixed width="160" label="职业">
                    <template slot-scope="scope">
                        <span v-for="(item, index) in scope.row.tradeWzryCareerList" :key="index">
                            <i v-if="index > 0">,</i>{{ item.careerName }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column width="100" label="英雄头像">
                    <template slot-scope="scope">
                        <imgBox :url="scope.row.icon" :width="80"/>
                    </template>
                </el-table-column>
                <el-table-column min-width="180" label="房间内队长背景">
                    <template slot-scope="scope">
                        <imgBox :url="scope.row.captainPic" :width="160"/>
                    </template>
                </el-table-column>
                <el-table-column min-width="140" label="房间内队员背景">
                    <template slot-scope="scope">
                        <imgBox :url="scope.row.teamUserPic" :width="120"/>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作">
                    <template slot-scope="scope">
                        <el-button @click="goHeroDetail(scope.row)" type="text" size="small">编辑</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'

export default {
    data () {
        return {
            pageNum: 1,
            pageSize: this._pageSize,
            keyWord: '',
            status: null,
            date: [],
            tableData: [],
            dialogParams: {
            },
            total: 0,
            isAddPay: false,
            loading: false,
            dialogVisible: false
        }
    },
    created () {
        this.getList(1)
    },
    methods: {
        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            let params = {
                pageNum,
                pageSize: this.pageSize
            }
            if (this.keyWord) {
                params.keyWord = this.keyWord
            }
            let res = await this.$http.get('/trade/selectWzydHeroInfo', {
                params
            })
            if (res.code === '0') {
                this.tableData = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        goHeroDetail (item) {
            let name = item.name
            const { href } = this.$router.resolve({
                path: '/team/heroDetail',
                query: {
                    name
                }
            })
            window.open(href, '_blank')
        },
        inputClear () {
            this.getList(1, 10)
        },
        selectChange () {
            this.type = ''
            this.sort = ''
            this.$refs.table.clearSort()
            this.getList(1, 10)
        },
        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },
        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        },
        tableFormatDate (time) {
            return formatDate(time, 'YYYY-MM-DD HH:MM:SS')
        }
    }
}
</script>

<style lang="scss" scoped>
    .debris-list {
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 10px 0 20px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }

        .table-box {
            margin: 20px 0;
            .cover {
                width: 80px;
                height: 80px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
            .desc {
                overflow: hidden;
                line-height: 20px;
                -webkit-line-clamp: 5;
                -webkit-box-orient: vertical;
                display: -webkit-box;
                height: 100px;
            }
            .user-icon {
                width: 20px;
                height: 20px;
                border-radius: 50%;
                margin-right: 5px;
                vertical-align: top;
            }
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
            .point {
                display:inline-block;
                width:10px;
                height:10px;
                border-radius: 50%;
                background-color:#67C23A;
                margin-right:3px;
            }
            .red-point {
                background-color: #F56C6C;
            }
        }

        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
        .dialog-reason {
            margin-top: 20px;
            p {
                margin-bottom: 10px;
            }
        }
    }
</style>
